#import BlackBoard.Activity;
import random;
import BlackBoard.InputSim;
import stgm;
from subprocess import call;

bReadXML = True;
sXmlFile = "./BlackBoard/XmlActs/ActsHmmAll.xml";
nSeed = 3;
inputSim = BlackBoard.InputSim(stgm, nSeed, nTimes=3, bReadXML=bReadXML, sXmlFile=sXmlFile);
#inputSim.printTransitionM();
#inputSim.printPriors();
inputSim.makeStateSpace();
#inputSim.printStateSpace();
#print "";

blackB = BlackBoard.BlackBoard(inputSim);
#print blackB.getNoisyOR([0.4,0.8,0.9]);
for sK in inputSim.aActs_Time:
    blackB.linkActivities(sK);
print "";
#if bReadXML==False: inputSim.printActivities();
blackB.graph.setup();

aNodes = [];
i = 0;
print "";
for sK in inputSim.aActs_Time:
    for j in range(len(inputSim.aActs_Time[sK])):
        aNodes.append(inputSim.aActs_Time[sK][j].rootAct);
    print i+1, "Priors:", blackB.graph.priorprob(aNodes);
    print i+1, "Posts:", blackB.graph.postprob(aNodes);
    i += 1;
    aNodes = [];

blackB.graph.write2dot(fname='./BlackBoard/DynBB-graph.dot');
call(['dot', '-Tpdf', './BlackBoard/DynBB-graph.dot', '-o', './BlackBoard/DynBB-graph.pdf']);
call(['evince', './BlackBoard/DynBB-graph.pdf']);
